/*
 * Powered By dico
 * Since 2017 - 2018
 */package com.seeyoui.kensite.bussiness.orderlang.reject.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;

import java.text.SimpleDateFormat;
import java.util.*;

import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;
import com.seeyoui.kensite.common.util.*;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.bussiness.orderlang.order.domain.OrderReportVO;
import com.seeyoui.kensite.bussiness.orderlang.order.domain.OrderStatisticsVO;
import com.seeyoui.kensite.bussiness.orderlang.purchaserUser.persistence.PurchaserUserMapper;
import com.seeyoui.kensite.bussiness.orderlang.reject.domain.Reject;
import com.seeyoui.kensite.bussiness.orderlang.reject.domain.RejectReportVO;
import com.seeyoui.kensite.bussiness.orderlang.reject.domain.RejectStatisticsVO;
import com.seeyoui.kensite.bussiness.orderlang.reject.persistence.RejectMapper;

/**
 * Reject
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-02-07
 */

@Service
public class RejectService extends BaseService {
	
	@Autowired
	private RejectMapper rejectMapper;
	@Autowired
	private PurchaserUserMapper purchaserUserMapper;
	
	/**
	 * 查询退单报表
	 * @param map
	 * @return
	 * @throws Exception 
	 */
	public List<RejectReportVO> findRejectReportByCondition(String customerType,String startTime,String endTime) throws Exception{
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("customerType", customerType);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		List<RejectReportVO> rejectReportList =  rejectMapper.findRejectReportByCondition(map);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if(rejectReportList.size() > 0){
			for (RejectReportVO rejectReportVO : rejectReportList) {
				rejectReportVO.setRejectTimeShow(sdf.format(rejectReportVO.getRejectTime()));
			}
		}
		return rejectReportList;
	}
	
	/**
	 * 查询退单统计信息
	 * @param map
	 * @return
	 */
	public RejectStatisticsVO findRejectStatistics(String customerType,String startTime,String endTime) throws Exception {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("customerType", customerType);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		RejectStatisticsVO rejectStatisticsVO = rejectMapper.findRejectStatistics(map);
		RejectStatisticsVO rejectCustomer = purchaserUserMapper.findRejectCustomer(map);
		if(rejectCustomer != null){
			rejectStatisticsVO.setRejectCustomer(rejectCustomer.getRejectCustomer());
		}else{
			rejectStatisticsVO.setRejectAmount("0");
			rejectStatisticsVO.setRejectCustomer("0");
		}
		return rejectStatisticsVO;
	}

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public Reject findOne(String id) throws CRUDException{
		return rejectMapper.findOne(id);
	}
	
	/**
	 * 查询数据集合
	 * @param reject
	 * @return
	 * @throws CRUDException
	 */
	public List<Reject> findList(Reject reject) throws CRUDException {
		return rejectMapper.findList(reject);
	}
	
	/**
	 * 查询所有数据集合
	 * @param reject
	 * @return
	 * @throws CRUDException
	 */
	public List<Reject> findAll(Reject reject) throws CRUDException {
		return rejectMapper.findAll(reject);
	}
	
	/**
	 * 查询数据总数
	 * @param reject
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(Reject reject) throws CRUDException {
		return rejectMapper.findTotal(reject);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param reject
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(Reject reject) throws CRUDException {
		return rejectMapper.findExTotal(reject);
	}
	
	/**
	 * 数据新增
	 * @param reject
	 * @throws CRUDException
	 */
	public void save(Reject reject) throws CRUDException{
		reject.preInsert();
		rejectMapper.save(reject);
	}
	
	/**
	 * 数据修改
	 * @param reject
	 * @throws CRUDException
	 */
	public void update(Reject reject) throws CRUDException{
		reject.preUpdate();
		rejectMapper.update(reject);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		rejectMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param reject
	 * @throws CRUDException
	 */
	public void remove(Reject reject) throws CRUDException{
		reject.preUpdate();
		rejectMapper.remove(reject);			
	}
	
}